import tkinter as tk
from playwright.async_api import async_playwright
import asyncio


async def get_page_title(url):
    async with async_playwright() as p:
        browser = await p.chromium.launch()
        page = await browser.new_page()
        await page.goto(url)
        title = await page.title()
        await browser.close()
    return title


async def update_title(url):
    title = await get_page_title(url)
    label['text'] = f'Title: {title}'


def on_click():
    url = entry.get()
    asyncio.run(update_title(url))


root = tk.Tk()
root.title("Playwright Tkinter Example")

label = tk.Label(root, text="Title: ")
label.grid(row=0, column=0)

entry = tk.Entry(root)
entry.grid(row=0, column=1)

button = tk.Button(root, text="Get Title", command=on_click)
button.grid(row=1, column=0, columnspan=2)

root.mainloop()
